//
//  BGView.m
//  ZXKlineDemo
//
//  Created by wanmeizty on 2018/5/4.
//  Copyright © 2018年 郑旭. All rights reserved.
//

#import "BGView.h"
#import "ZXAssemblyView.h"

@interface BGView()

@property (nonatomic,strong) ZXAssemblyView * assenblyView;
@property (nonatomic,strong) NSMutableArray * dataArray;

@end
@implementation BGView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self createUI];
    }
    return self;
}

- (void)createUI{
    [self addSubview:self.assenblyView];
    [self firstconfigureData];
}

- (void)firstconfigureData
{
    //数据处理
    //    NSMutableArray *transformedDataArray = [NSMutableArray arrayWithCapacity:0];
    //    for (int i = 0; i < 1; i ++) {
    //
    //        model = nil;
    //    }
    KlineModel * model = [[KlineModel alloc] init];
    model.timestamp = 1504182600;
    model.closePrice = 0.76039;
    model.openPrice = 0.7613;
    model.highestPrice = 0.76134;
    model.lowestPrice = 0.76031;
    model.volumn = @169;
    NSArray * transformedDataArray = @[model];
    [self.dataArray addObjectsFromArray:transformedDataArray];
    
    
    
    
    //绘制k线图
    [self.assenblyView drawHistoryCandleWithDataArr:self.dataArray precision:5 stackName:@"股票名" needDrawQuota:@"CDMA"];
    
    //如若有socket实时绘制的需求，需要实现下面的方法
    //socket
    //创建定时器,并设置代理接收
    //    [ZXSocketDataReformer sharedInstance].delegate = self;
    //    [[ZXSocketDataReformer sharedInstance] shouldToCreatTimerWithDataArray:self.dataArray];
    
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark - Getters & Setters
- (ZXAssemblyView *)assenblyView
{
    if (!_assenblyView) {
        _assenblyView = [[ZXAssemblyView alloc] init];
//        _assenblyView.delegate = self;
        _assenblyView.frame = CGRectMake(0, 0, TotalWidth, 185);
    }
    return _assenblyView;
}

@end
